<?php

class MoviehubDataParser extends DOMDataParser {

    public function parseData($data) {
        $dom = new DOMDocument();
        if (!@$dom->loadHTML(mb_convert_encoding($data, 'HTML-ENTITIES', $this->encoding))) {
            $dom = false;
        } else {
            $dom = $this->rewriteAbsoluteUrls($dom);
        }
        $device = $this->getOption('device');
        $arr = array('src' => '', 'type' => '');
        if ($dom) {
            $mediaBlock = $dom->getElementById('media');
            if ($mediaBlock->textContent != '') {
                $media = $mediaBlock->getElementsByTagName('embed');
                if ($device == 'iphone') {
                    $arr['type'] = 'ilc-compliant-iphone';
                    $url1 = $mediaBlock->parentNode->nodeValue;
                    $urlArr1 = explode('src',$url1);
                    $urlArr2 = explode('\'',$urlArr1[1]);
                    $arr['src'] = $urlArr2[1];
                } else if ($device == 'android') {
                    $arr['type'] = 'ilc-tablet-android';
                    $metas = $dom->getElementsByTagName('meta');
                    $url = $metas->item(8)->attributes->item(1);
                    $urlArr = explode('video/', $url->textContent);
                    $arr['src'] = $urlArr[0];
                } else {
                    $arr['type'] = 'ilc';
                    $arr['src'] = $media->item(0)->attributes->item(5)->value;
                }
            } else {
                $media = $mediaBlock->getElementsByTagName('iframe');
                $arr['src'] = $media->item(0)->attributes->item(2)->value;
                $arr['type'] = 'ilc_youtube';
            }
        }
        return $arr;
    }
}
